from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dim.dim_lmdm_sys_customer import jms_dim__dim_lmdm_sys_customer
from jms.dim.dim_sys_customer_additional_base import jms_dim__dim_sys_customer_additional_base
from jms.dim.dim_project_work_order_type import jms_dim__dim_project_work_order_type
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from jms.dwd.dwd_warhouse.dwd_wide_unsign_summary_waybill_dt import jms_dwd__dwd_wide_unsign_summary_waybill_dt
from jms.dwd.sqs.work_order_duplicate.dwd_work_order_new_base_dt import jms_dwd__dwd_work_order_new_base_dt
from jms.dwd.sqs.work_order_duplicate.dwd_claim_work_order_new_base_dt import jms_dwd__dwd_claim_work_order_new_base_dt
from jms.dwd.sqs.work_order_duplicate.dwd_project_work_order_new_base_dt import jms_dwd__dwd_project_work_order_new_base_dt
from jms.dwd.sqs.work_order_duplicate.dwd_appeal_info_new_base_dt import jms_dwd__dwd_appeal_info_new_base_dt
from jms.dwd.sqs.dwd_sqs_problem_express_wo_base_dt import jms_dwd__dwd_sqs_problem_express_wo_base_dt
from jms.dwd.sqs.dwd_arbitration_base_dt import jms_dwd__dwd_arbitration_base_dt
from jms.dwd.sqs.dwd_sqs_objection_info_base_dt import jms_dwd__dwd_sqs_objection_info_base_dt
jms_dwd__dwd_wide_customer_order_waybill_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_customer_order_waybill_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    execution_timeout=timedelta(minutes=50),
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dwd__dwd_wide_customer_order_waybill_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_wide_customer_order_waybill_dt/execute.hql',
    driver_memory='8G',
    driver_cores=4,
    executor_cores=5,
    executor_memory='16G',
    num_executors=40,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 60,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 300,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 480,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.sql.autoBroadcastJoinThreshold': 104857600,
          'spark.yarn.executor.memoryOverhead': 8192,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
                 'hive.exec.dynamic.partition.mode': 'nonstrict',
                 'hive.exec.max.dynamic.partitions': 400,  # 每天生成 20 个分区
                 'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
                 },
    yarn_queue='pro',
)

jms_dwd__dwd_wide_customer_order_waybill_dt << [
    jms_dim__dim_lmdm_sys_customer,
    jms_dim__dim_sys_customer_additional_base,
    jms_dwd__dwd_yl_oms_oms_order_incre_dt,
    jms_dwd__dwd_wide_unsign_summary_waybill_dt,
    jms_dim__dim_project_work_order_type,
    jms_dwd__dwd_work_order_new_base_dt,
    jms_dwd__dwd_claim_work_order_new_base_dt,
    jms_dwd__dwd_project_work_order_new_base_dt,
    jms_dwd__dwd_appeal_info_new_base_dt,
    jms_dwd__dwd_sqs_problem_express_wo_base_dt,
    jms_dwd__dwd_arbitration_base_dt,
    jms_dwd__dwd_sqs_objection_info_base_dt,
]
